﻿package net.wangit.etl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.wangit.User;
import net.wangit.context.ActionContext;
import net.wangit.util.Checker;


/**
 * 数据交换工具类
 * 
 * @author watson
 * 
 */
public class ETLUtil {

	private static final DateFormat FORMAT = new SimpleDateFormat(
			"yyyy.MM.dd.HH.mm.ss.SSS");

	public ETLUtil() {
	}

	public static String getPath(String pathPrefix, String tableName,
			int fileCount) {
		if (Checker.isEmpty(pathPrefix))
			pathPrefix = (new StringBuilder(ETLSettings.getRoot())).append(
					tableName).toString();
		return (new StringBuilder(pathPrefix)).append(".").append(fileCount)
				.append(".xml").toString();
	}

	public static String getBatchId(ActionContext ac) {
		User user = ac.getVisitor().getUser();
		return (new StringBuilder(FORMAT.format(new Date()))).append(".")
				.append(user.getId()).toString();
	}

	public static String toXmlValue(String value) {
		return value != null ? value : "$N%";
	}

	public static String toDBValue(String value) {
		return "$N%".equals(value) ? null : value;
	}

}
